package com.societyGames.loading
{
import com.societyGames.system.EventObject;
import flash.events.EventDispatcher;
import com.societyGames.utility.XMLUtility;

import flash.utils.getTimer;

/**
 * Load an XML from an URL using cache busting.
 * @author
 */
public class UrlXMLLoadStep extends EventDispatcher implements ILoadStep
{
    private var _completeEventObject:EventObject;
    private var _url:String;
    private var _callback:Function /*function(xml:XML)void*/

    public function UrlXMLLoadStep(url:String, callback:Function /*function(xml:XML):void*/)
    {
        this._completeEventObject = new EventObject(this, "COMPLETE");
        this._url = url;
        this._callback = callback;
    }

    //ILoadStep-->
    public function get completeEventObject():EventObject
    {
        return this._completeEventObject;
    }

    public function load():void
    {
        XMLUtility.loadXMLFromURL(this._url + "?cache=" + getTimer(), onXMLLoad);
    }
    //<--ILoadStep

    private function onXMLLoad(xml:XML):void
    {
        this._callback(xml);
        this._completeEventObject.dispatchEvent();
    }
}
}